{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "_index.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "private_outputs": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "metadata": {
        "id": "MrkvnwgKeAlu",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "##### Copyright 2018 The TensorFlow Authors.\n",
        "\n",
        "Licensed under the Apache License, Version 2.0 (the \"License\");"
      ]
    },
    {
      "metadata": {
        "id": "XENCytU5eFfR",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\"); { display-mode: \"form\" }\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "uTFzoTAbeL5t",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "# Get Started with TensorFlow Probability"
      ]
    },
    {
      "metadata": {
        "id": "Px42Z5G7ei80",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://www.tensorflow.org/probability\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
        "  </td>\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/probability/blob/master/tensorflow_probability/g3doc/_index.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
        "  </td>\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://github.com/tensorflow/probability/tree/master/tensorflow_probability/g3doc/_index.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
        "  </td>\n",
        "</table>"
      ]
    },
    {
      "metadata": {
        "id": "YcJ-AKyGfQ75",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "This is a [Google Colaboratory](https://colab.research.google.com/notebooks/welcome.ipynb) notebook file. Python programs are run directly in the browser—a great way to learn and use TensorFlow. To run the Colab notebook:\n",
        "\n",
        "1. Connect to a Python runtime: At the top-right of the menu bar, select *CONNECT*.\n",
        "2. Run all the notebook code cells: Select *Runtime* > *Run all*.\n",
        "\n",
        "For more examples and guides (including details for this program), see [Get Started with TensorFlow](https://www.tensorflow.org/tutorials/)."
      ]
    },
    {
      "metadata": {
        "id": "l91Ivw7Zfa2c",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "Import the TensorFlow and TensorFlow Probability modules into your program. Enable [eager execution](https://www.tensorflow.org/guide/eager) to display the output as we go:"
      ]
    },
    {
      "metadata": {
        "id": "0ensrchgdNnW",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "import tensorflow as tf\n",
        "import tensorflow_probability as tfp\n",
        "\n",
        "tf.enable_eager_execution()\n",
        "\n",
        "print(tf.__version__)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "rcANmCk2vJG0",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# Pretend to load synthetic data set.\n",
        "features = tfp.distributions.Normal(loc=0., scale=1.).sample(int(100e3))\n",
        "labels = tfp.distributions.Bernoulli(logits=1.618 * features).sample()\n",
        "\n",
        "# Specify model.\n",
        "model = tfp.glm.Bernoulli()\n",
        "\n",
        "# Fit model given data.\n",
        "coeffs, linear_response, is_converged, num_iter = tfp.glm.fit(\n",
        "    model_matrix=features[:, tf.newaxis],\n",
        "    response=tf.cast(labels, dtype=tf.float32),\n",
        "    model=model)\n",
        "\n",
        "print(coeffs)  # ==> coeffs is approximately [1.618] (We're golden!)"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}